package com.cgwx.tcservice.service.impl;

import com.cgwx.commonutils.JwtUtils;
import com.cgwx.tcservice.entity.bean.TcSendParam;
import com.cgwx.tcservice.entity.tc.TcInfoLog;
import com.cgwx.tcservice.mapper.TcInfoLogMapper;
import com.cgwx.tcservice.service.TcInfoLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 遥控指令记录表 服务实现类
 * </p>
 *
 * @author GaoWei
 * @since 2023-09-25
 */
@Service
public class TcInfoLogServiceImpl extends ServiceImpl<TcInfoLogMapper, TcInfoLog> implements TcInfoLogService {

//    记录过程指令内容
    @Override
    public void saveTcInfo(HttpServletRequest request, TcSendParam tcSendParam, String tcMessage) {
        TcInfoLog tcInfoLog = new TcInfoLog();
        tcInfoLog.setTcCommandCode(tcSendParam.getTcSendCommand().getTcCommandCode());
        tcInfoLog.setTcCommandName(tcSendParam.getTcSendCommand().getTcCommandName());
        tcInfoLog.setTcCommandValue(tcMessage);
        tcInfoLog.setDataChannel(tcSendParam.getTcSendChannel());
        tcInfoLog.setUsername(JwtUtils.getUsername(request.getHeader("token")));
        baseMapper.insert(tcInfoLog);
    }
}
